#ifndef RGSMAPTOOLSELECTIONHANDLER_H
#define RGSMAPTOOLSELECTIONHANDLER_H
#include<QtMath>
#include<qgsrubberband.h>
#include<qgsmapmouseevent.h>
#include<QApplication>
class QgsMapCanvas;

class RgsMapToolSelectionHandler:public QObject
{
    Q_OBJECT
public:
    //! Select features to identify by:
    enum SelectionMode
    {
        //! SelectSimple - single click or drawing a rectangle, default option
        SelectSimple,
        //! SelectPolygon - drawing a polygon or right-click on existing polygon feature
        SelectPolygon,
        //! SelectFreehand - free hand selection
        SelectFreehand,
        //! SelectRadius - a circle selection
        SelectRadius
    };
    Q_ENUM( SelectionMode )
    RgsMapToolSelectionHandler( QgsMapCanvas *canvas,
                               RgsMapToolSelectionHandler::SelectionMode selectionMode = RgsMapToolSelectionHandler::SelectionMode::SelectSimple);

    ~RgsMapToolSelectionHandler() override;



    //! Overridden mouse move event
    void canvasMoveEvent( QgsMapMouseEvent *e );

    //! Overridden mouse press event
    void canvasPressEvent( QgsMapMouseEvent *e );

    //! Overridden mouse release event
    void canvasReleaseEvent( QgsMapMouseEvent *e );


    void initRubberBand();

    void selectFeaturesPressEvent(QgsMapMouseEvent * e);
    void selectFeaturesMoveEvent(QgsMapMouseEvent * e);
    void selectFeaturesReleaseEvent(QgsMapMouseEvent * e);
    void selectPolygonPressEvent(QgsMapMouseEvent * e);



    void setSelectedGeometry( const QgsGeometry &geometry, Qt::KeyboardModifiers modifiers );
    QgsPointXY toMapCoordinates(QPoint point);
    QgsGeometry selectedGeometry();

signals:
    void geometryChanged(Qt::KeyboardModifiers modifiers);


protected:
    QgsMapCanvas *mCanvas = nullptr;
    std::unique_ptr<QgsRubberBand> mSelectionRubberBand;
    QgsGeometry mSelectionGeometry;
    bool mSelectionActive = false;
    SelectionMode mSelectionMode = SelectSimple;

    QPoint mInitDragPos;
    QgsPointXY mRadiusCenter;



    QColor mFillColor = QColor( 254, 178, 76, 63 );
    QColor mStrokeColor = QColor( 254, 58, 29, 100 );
};

#endif // RGSMAPTOOLSELECTIONHANDLER_H
